GObject.ParamFlags.READABLE,
false),
},
+ Signals: {
+ 'screenshot-taken': {param_types: [Gio.File.$gtype]},
+ 'closed': {},
+ },
}, class ScreenshotUI extends St.Widget {
_init() {
super._init({
this._areaSelector.reset();
for (const selector of this._windowSelectors)
selector.reset();
+
+ this.emit('closed');
}
close(instantly = false) {
_onCaptureButtonClicked() {
if (this._shotButton.checked) {
- this._saveScreenshot();
+ this._saveScreenshot().catch(logError);
this.close();
} else {
// Screencast closes the UI on its own.
}
}
- _saveScreenshot() {
+ async _saveScreenshot() {
+ let file = null;
+
if (this._selectionButton.checked || this._screenButton.checked) {
const content = this._stageScreenshot.get_content();
if (!content)
if (!this._cursor.visible)
cursorTexture = null;
- captureScreenshot(
- texture, geometry, this._scale,
- {
- texture: cursorTexture ?? null,
- x: this._cursor.x * this._scale,
- y: this._cursor.y * this._scale,
- scale: this._cursorScale,
- }
- ).catch(e => logError(e, 'Error capturing screenshot'));
+ try {
+ file = await captureScreenshot(
+ texture, geometry, this._scale,
+ {
+ texture: cursorTexture ?? null,
+ x: this._cursor.x * this._scale,
+ y: this._cursor.y * this._scale,
+ scale: this._cursorScale,
+ }
+ );
+ } catch (e) {
+ logError(e, 'Error capturing screenshot');
+ }
} else if (this._windowButton.checked) {
const window =
this._windowSelectors.flatMap(selector => selector.windows())
if (!this._cursor.visible)
cursorTexture = null;
- captureScreenshot(
- texture,
- null,
- window.bufferScale,
- {
- texture: cursorTexture ?? null,
- x: window.cursorPoint.x * window.bufferScale,
- y: window.cursorPoint.y * window.bufferScale,
- scale: this._cursorScale,
- }
- ).catch(e => logError(e, 'Error capturing screenshot'));
+ try {
+ file = await captureScreenshot(
+ texture,
+ null,
+ window.bufferScale,
+ {
+ texture: cursorTexture ?? null,
+ x: window.cursorPoint.x * window.bufferScale,
+ y: window.cursorPoint.y * window.bufferScale,
+ scale: this._cursorScale,
+ }
+ );
+ } catch (e) {
+ logError(e, 'Error capturing screenshot');
+ }
}
+
+ if (file)
+ this.emit('screenshot-taken', file);
}
async _startScreencast() {